import random
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


def send_code(msg_to):
    email_name = '42197393@qq.com'  # 发送方邮箱
    passwd = '这个写你自己的授权码'  # 填入发送方邮箱的授权码
    # 不要，千万不要写我的授权码，你一定要写你自己的授权码！！！
    code = random.randint(10000,99999)
    # 正文
    content = """
    您的验证码是:<h1 style='color:red'>{}</h1>
    """.format(code)

    msg = MIMEMultipart()
    msg["Subject"] = "慕慕手记验证码"
    msg["From"] = "慕慕手记"
    msg["To"] = msg_to
    # 发送邮件正文，html格式的
    msg.attach(MIMEText(content,"html","utf-8"))
    s = smtplib.SMTP_SSL("smtp.qq.com",465)  # 邮箱服务器及端口号
    s.login(email_name,passwd)
    s.sendmail(email_name,msg_to,msg.as_string())
    return code